package jehc.djshi.sys.service.impl;
import java.io.File;
import java.util.List;
import java.util.Map;

import jehc.djshi.common.util.AllUtils;
import jehc.djshi.sys.dao.XtEncoderqrcodeDao;
import jehc.djshi.sys.model.XtEncoderqrcode;
import jehc.djshi.sys.service.XtEncoderqrcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import jehc.djshi.common.base.BaseService;
import jehc.djshi.common.util.ExceptionUtil;

/**
 * @Desc 平台二维码
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service("xtEncoderqrcodeService")
public class XtEncoderqrcodeServiceImpl extends BaseService implements XtEncoderqrcodeService {
	@Autowired
	private XtEncoderqrcodeDao xtEncoderqrcodeDao;
	/**
	* 分页
	* @param condition 
	* @return
	*/
	public List<XtEncoderqrcode> getXtEncoderqrcodeListByCondition(Map<String,Object> condition){
		try{
			return xtEncoderqrcodeDao.getXtEncoderqrcodeListByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 查询对象
	* @param xt_encoderQRCode_id 
	* @return
	*/
	public XtEncoderqrcode getXtEncoderqrcodeById(String xt_encoderQRCode_id){
		try{
			return xtEncoderqrcodeDao.getXtEncoderqrcodeById(xt_encoderQRCode_id);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 添加
	* @param xtEncoderqrcode
	* @return
	*/
	public int addXtEncoderqrcode(XtEncoderqrcode xtEncoderqrcode){
		int i = 0;
		try {
			String newName = AllUtils.getRandom()+".png";
			String path = getXtPathCache("xt_encoderqrcode_default_path").get(0).getXt_path();
			String relative_path = getXtPathCache("xt_encoderqrcode_relative_path").get(0).getXt_path();
			File f = new File(path);
			if(!f.exists()){
				f.mkdirs();
			}
			xtEncoderqrcode.setCreate_id(getXtUid());
			xtEncoderqrcode.setCreate_time(getDate());
////			twoDimensionCode.encoderQRCode(xtEncoderqrcode.getXt_encoderqrcode_url(), path+newName, "png");
//			XtAttachment xt_Attachment = new XtAttachment();
//			xt_Attachment.setXt_attachment_id(UUID.toUUID());
//			xt_Attachment.setXt_attachmentCtime(DateUtil.getSimpleDateFormat());
//			xt_Attachment.setXt_attachmentName(newName);
//			xt_Attachment.setXt_attachmentPath(relative_path+newName);
//			xt_Attachment.setXt_userinfo_id(getXtUid());
//			xt_Attachment.setXt_attachmentType("image/png");
//			xt_Attachment.setXt_attachmentTitle(xtEncoderqrcode.getXt_encoderqrcode_title());
//			xt_Attachment.setXt_userinfo_id(getXtUid());
//			xtAttachmentService.addXtAttachment(xt_Attachment);
//			xtEncoderqrcode.setXt_attachment_id(xt_Attachment.getXt_attachment_id());
			i = xtEncoderqrcodeDao.addXtEncoderqrcode(xtEncoderqrcode);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 修改
	* @param xtEncoderqrcode
	* @return
	*/
	public int updateXtEncoderqrcode(XtEncoderqrcode xtEncoderqrcode){
		int i = 0;
		try {
			xtEncoderqrcode.setUpdate_id(getXtUid());
			xtEncoderqrcode.setUpdate_time(getDate());
			String newName = AllUtils.getRandom()+".png";
			String path = getXtPathCache("xt_encoderqrcode_default_path").get(0).getXt_path();
			String relative_path = getXtPathCache("xt_encoderqrcode_relative_path").get(0).getXt_path();
			File f = new File(path);
			if(!f.exists()){
				f.mkdirs();
			}
//			XtAttachment xt_Attachment = new XtAttachment();
//			xt_Attachment.setXt_attachment_id(UUID.toUUID());
//			xt_Attachment.setXt_attachmentCtime(getSimpleDateFormat());
//			xt_Attachment.setXt_attachmentName(newName);
//			xt_Attachment.setXt_attachmentPath(relative_path+newName);
//			xt_Attachment.setXt_userinfo_id(getXtUid());
//			xt_Attachment.setXt_attachmentType("image/png");
//			xt_Attachment.setXt_attachmentTitle(xtEncoderqrcode.getXt_encoderqrcode_title());
//			xt_Attachment.setXt_userinfo_id(getXtUid());
//			xtAttachmentService.addXtAttachment(xt_Attachment);
//			xtEncoderqrcode.setXt_attachment_id(xt_Attachment.getXt_attachment_id());
			i = xtEncoderqrcodeDao.updateXtEncoderqrcode(xtEncoderqrcode);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 删除
	* @param condition 
	* @return
	*/
	public int delXtEncoderqrcode(Map<String,Object> condition){
		int i = 0;
		try {
			i = xtEncoderqrcodeDao.delXtEncoderqrcode(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
}
